<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目类型">
              <j-dict-select-tag placeholder="请选择项目类型" v-model="queryParam.type" dictCode="property_type"/>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目状态">
              <j-dict-select-tag placeholder="请选择项目状态" v-model="queryParam.state" dictCode="property_state"/>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属区域">
              <JAreaLinkagePca  @change="areaChange" ></JAreaLinkagePca>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目编号">
<!--              <a-input placeholder="请输入资产编号" v-model="queryParam.propertyNo"></a-input>-->
              <j-input placeholder="请输入账号模糊查询" v-model="queryParam.propertyNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
<!--              <a-input placeholder="请输入资产名称" v-model="queryParam.propertyName"></a-input>-->
              <j-input placeholder="请输入账号模糊查询" v-model="queryParam.propertyName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="渠道方">
<!--              <a-input placeholder="请输入渠道方" v-model="queryParam.channelName"></a-input>-->
              <a-select  @change="handleChange" v-model="defaultValue"  placeholder="请选择渠道方">
                <a-select-option :value="i.id" v-for="(i,index) in arr" >
                  {{i.channelName}}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">


          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!--<a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd1" type="primary" icon="plus" v-has="'channel_manager'">转让申请</a-button>
<!--      <a-button @click="handleAdd1" type="primary" icon="plus" >转让申请</a-button>-->
      <!--<a-button type="primary" icon="download" @click="handleExportXls('资产转让')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <!--状态颜色-->
        <template slot="state_dictText" slot-scope="text,record">
          <div v-html="text" v-if="record.state == '-1'" style="color: #eb2f96;"></div>
          <div v-html="text" v-else-if="record.state == '4'" style="color: #00DB00;"></div>
          <div v-html="text" v-else-if="record.state > 4 && record.state < 12" style="color: purple;"></div>
          <div v-html="text" v-else-if="record.state == '12'" style="color: dodgerblue;"></div>
          <div v-html="text" v-else-if="record.state == '14'" style="color: orange;"></div>
          <div v-html="text" v-else></div>
        </template>
        <!--<template slot="province" slot-scope="text">
          <div>{{getPcaText(text)}}</div>
        </template>-->
        <template slot="city" slot-scope="text">
          <div>{{getPcaText(text)}}</div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
<!--          <span v-if="record.state=='0'" v-has="'risk_control_officer'">-->
          <span v-show="record.state=='0'"  v-has="'risk_control_officer'">
            <a @click="handleEdit1(record)">审核</a>
            <a-divider type="vertical" />
          </span>
          <span v-show="record.state=='-1'"  >
            <a @click="handleEdit(record)">修改</a>
            <a-divider type="vertical" />
            <a @click="handleSee(record)">拒审原因</a>
            <a-divider type="vertical" />
          </span>
<!--          <span v-if="record.state == '1'" v-has="'risk_control_manager'">-->
          <span v-show="record.state == '1'"  v-has="'risk_control_manager'">
            <a @click="handleEdit1(record)">复核</a>
            <a-divider type="vertical" />
          </span>
<!--          <span v-if="record.state == '4'" v-has="'customer_manager'">-->
          <span v-show="record.state == '4'"  v-has="'customer_manager'">
            <a @click="handleGrounding(record)">挂牌</a>
            <a-divider type="vertical" />
          </span>
<!--          <span v-if="record.state == 10" v-has="'customer_manager'">-->
          <span  v-show="record.state == 10" v-has="'customer_manager'">
            <a @click="handleChengjiao(record)">成交</a>
            <a-divider type="vertical" />
            <a @click="handleLiupai(record)">流拍</a>
            <a-divider type="vertical" />
          </span>
          <span v-if="record.state > 4" >
            <a @click="handleAuction(record)">报名明细</a>
            <a-divider type="vertical" />
          </span>
<!--          <span v-if="record.state!='0'&&record.state!='1'">-->
          <span>
            <a @click="handleDetail1(record)">详情</a>
          </span>

          <!--<a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />-->
          <!--<a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>-->
        </span>

      </a-table>
    </div>

    <property-modal ref="modalForm" @ok="modalFormOk"></property-modal>
    <PropertyEditModal ref="modalEditForm" @ok="modalFormOk"></PropertyEditModal>
    <PropertyEditModal1 ref="modalEditForm1" @ok="modalFormOk"></PropertyEditModal1>
    <PropertyGroundModal ref="modalGroundForm" @ok="modalFormOk"></PropertyGroundModal>
    <AuctionModal ref="modalAuction" @ok="modalFormOk"></AuctionModal>
    <ChengjiaoModal ref="ChengjiaoModal" @ok="modalFormOk"></ChengjiaoModal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin1'
  import PropertyModal from './modules/PropertyModal'
  import PropertyEditModal from './modules/PropertyEditModal'
  import PropertyEditModal1 from './modules/PropertyEditModal1'
  import PropertyGroundModal from './modules/PropertyGroundModal'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import AreaPca from '@/components/_util/AreaPca'
  import { getAction,putAction} from '@/api/manage'
  import AuctionModal from '@/views/auctionenroll/AuctionModal'
  import ChengjiaoModal from './modules/ChengjiaoModal'
  import JAreaLinkagePca from '@/components/jeecg/JAreaLinkagePca'
  import JInput from '@/components/jeecg/JInput'

  export default {
    name: 'PropertyList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JDictSelectTag,
      PropertyModal,
      PropertyEditModal,
      PropertyGroundModal,
      PropertyEditModal1,
      AuctionModal,
      ChengjiaoModal,
      JAreaLinkagePca,
      JInput
    },
    data () {
      return {
        description: '资产转让管理页面',
        defaultValue:'请选择',
        arr:[],
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'资产编号',
            align:"center",
            dataIndex: 'propertyNo'
          },{
            title:'名称',
            align:"center",
            dataIndex: 'propertyName'
          },
          {
            title:'资产类型',
            align:"center",
            dataIndex: 'type_dictText'
          },
          {
            title:'地区',
            align:"center",
            dataIndex: 'city',
            scopedSlots: { customRender: 'city' }
          },
          {
            title:'挂牌价格',
            align:"center",
            dataIndex: 'listingPrice',
            customRender: (t,r,index)=> {
              return t+'万元';
            }
          },
          {
            title:'保证金',
            align:"center",
            dataIndex: 'earnestMoney',
            customRender: (t,r,index)=> {
              // return this.formatNumber(t)+'元';
              // return t/10000+'万元';
              return t+'元';
            }
          },
          {
            title:'渠道方',
            align:"center",
            dataIndex: 'createBy'
          },
          /*{
            title:'省',
            align:"center",
            dataIndex: 'province',
            scopedSlots: { customRender: 'province' }
          },*/

          {
            title:'资产状态',
            align:"center",
            dataIndex: 'state_dictText',
            scopedSlots: { customRender: 'state_dictText' }
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/property/list",
          delete: "/property/delete",
          deleteBatch: "/property/deleteBatch",
          exportXlsUrl: "/property/exportXls",
          importExcelUrl: "property/importExcel",
          queryById: "/property/propertyGrounding",
          queryById1: "/property/queryById",
          streamBeatAndDeal:"/property/streamBeatAndDeal",
          getAuctionList:"auctionEnroll/getAuctionList/",//获取中标人下拉列表接口
          getChannelList:"/property/getChannelList",//获取渠道方列表
          getRoleCode:"/property/getRoleCode"//获取权限列表
        },
        dictOptions:{},
        pcaData:''
      }
    },
    created() {
      this.pcaData = new AreaPca()
      /*
      * customer_manager 客户经理
      * channel_manager 渠道经理
      * risk_control_manager 风控经理
       * risk_control_officer 风控专员
       * third_role 第三方登录角色
       * hr 人力资源部
       * admin 管理员
       * test 临时角色
      * */
      //获取登录账户权限所属 用来判断初始审核状态列表
      getAction(this.url.getRoleCode).then((res)=>{
        console.log('res',res)
        if (res.message == 'risk_control_officer'){
          this.queryParam.state=0
        }else if(res.message == 'risk_control_manager'){
          this.queryParam.state=1
        }else {
          this.queryParam={}

        }
      }).finally(()=>{
        this.loadData()
      })


      getAction(this.url.getChannelList).then((res)=>{
        console.log(res)
        if (res.success){
          this.arr = res.result
        }else {
          this.$message.error(res.message)
        }
      })
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      //反推省市

      getPcaText(code){
        return this.pcaData.getText(code);
      },

      //状态为0的审核
      handleEdit0: function (record) {
        /*this.$refs.modalEditForm.edit(record);
        this.$refs.modalEditForm.title = "审核";
        this.$refs.modalEditForm.disableSubmit = false;
        this.$refs.modalEditForm.details = true;*/
      },
      handleEdit1: function (record) {
        this.loading=true
        getAction(this.url.queryById1, { id:record.id }).then((res)=>{
          console.log('res',res)
          if(res.success){
            if (res.result.imgList){
              for (let re of res.result.imgList) {
                console.log(re)
                let img = new Image()
                img.src = re
              }
              this.$refs.modalEditForm.imgList1=true
              this.$refs.modalEditForm.edit(res.result);
              this.$refs.modalEditForm.title = "审核";
              this.$refs.modalEditForm.disableSubmit = false;
              this.$refs.modalEditForm.details = true;
            }else {
              this.$refs.modalEditForm.imgList1=false
              this.$refs.modalEditForm.edit(res.result);
              this.$refs.modalEditForm.title = "审核";
              this.$refs.modalEditForm.disableSubmit = false;
              this.$refs.modalEditForm.details = true;
            }

          }else {
            this.$message.error('获取详情信息出错!')
          }
        }).finally(()=>{
          this.loading=false
        })

      },
      //新增
      handleAdd1: function () {
        this.$refs.modalForm.add();
        this.$refs.modalForm.title = "新增";
        this.$refs.modalForm.disableSubmit = false;
      },
      //修改
      handleEdit: function (record) {
        this.loading = true
        getAction(this.url.queryById1, { id:record.id }).then((res)=>{
          console.log('res',res)
          let imgList = res.result.imgList.join(',')
          let record1 = Object.assign(record,{urls:imgList})
          this.$refs.modalForm.edit(record);
          this.$refs.modalForm.title = "修改";
          this.$refs.modalForm.disableSubmit = false;
        }).finally(()=>{
          this.loading=false
        })

      },

      //拒审原因
      handleSee(record){
        this.loading = true
        getAction(this.url.queryById1, { id:record.id }).then((res)=>{
          console.log('res',res)
          this.$error({
            title: '拒审原因',
            content: res.result.remark,
          });
        }).finally(()=>{
          this.loading=false
        })

      },



      //详情
      handleDetail1:function(record){
        this.loading=true
        getAction(this.url.queryById1, { id:record.id }).then((res)=>{
          // console.log('res',res.result.enrollEndTime)
          if(res.success){
            if (res.result.imgList){
              for (let re of res.result.imgList) {
                console.log(re)
                let img = new Image()
                img.src = re
              }
              this.$refs.modalEditForm1.imgList1=true
              this.$refs.modalEditForm1.edit(res.result);
              this.$refs.modalEditForm1.title="详情";
              this.$refs.modalEditForm1.disableSubmit = true;
              this.$refs.modalEditForm1.details = false;
            }else {
              this.$refs.modalEditForm1.imgList1=false
              this.$refs.modalEditForm1.edit(res.result);
              this.$refs.modalEditForm1.title="详情";
              this.$refs.modalEditForm1.disableSubmit = true;
              this.$refs.modalEditForm1.details = false;
            }

          }else {
            this.$message.error('获取详情信息出错!')
          }
        }).finally(()=>{
          this.loading=false
        })
        //旧的
        // this.$refs.modalEditForm1.edit(record);
        // this.$refs.modalEditForm1.title="详情";
        // this.$refs.modalEditForm1.disableSubmit = true;
        // this.$refs.modalEditForm1.details = false;

      },
      //报名
      handleGrounding(record){
        this.$refs.modalGroundForm.edit(record);
        this.$refs.modalGroundForm.title="挂牌";
        this.$refs.modalGroundForm.disableSubmit = false;

      },
      //报名明细
      handleAuction(record){
        this.$refs.modalAuction.add(record);
        this.$refs.modalAuction.title = "报名明细";
        this.$refs.modalAuction.disableSubmit = false;
      },
      //成交
      handleChengjiao(record){

        getAction(this.url.getAuctionList+record.id).then((res)=>{
          console.log(res)
          if (res.success){
            let record1 = Object.assign(record,{list:res.result})
            this.$refs.ChengjiaoModal.state = 12
            this.$refs.ChengjiaoModal.edit(record1);
            this.$refs.ChengjiaoModal.title = "交易成交";
            this.$refs.ChengjiaoModal.disableSubmit = false;
          }else {
            this.$message.error(res.message)
          }
        })




        /*putAction(this.url.streamBeatAndDeal,{id:record.id,state:12}).then((res)=>{
          console.log(res)
          if (res.success){
            this.$message.success(res.message)
          }else {
            this.$message.error(res.message)
          }
        }).finally(()=>{
          this.loadData();
        })*/




      },
      //流拍
      handleLiupai(record){
        getAction(this.url.getAuctionList+record.id).then((res)=>{
          console.log(res)
          if (res.success){
            let record1 = Object.assign(record,{list:res.result})
            this.$refs.ChengjiaoModal.state = 14
            this.$refs.ChengjiaoModal.edit(record1);
            this.$refs.ChengjiaoModal.title = "流拍";
            this.$refs.ChengjiaoModal.disableSubmit = false;
          }else {
            this.$message.error(res.message)
          }
        })
        /*putAction(this.url.streamBeatAndDeal,{id:record.id,state:14}).then((res)=>{
          console.log(res)
          if (res.success){
            this.$message.success(res.message)
          }else {
            this.$message.error(res.message)
          }
        }).finally(()=>{
          this.loadData();
        })*/

      },


      //地区查询
      areaChange(e){
        console.log(e)
        /*this.province = e[0]
        this.city = e[1]*/
        this.queryParam.city = e[1]
      },



      //查询状态
      handleChange(e){
        console.log(e)
        // this.$refs.xuanze.value = e.toString()
        this.defaultValue = e
        this.queryParam.channelName = e
      },

      //查询重置
      searchReset() {
        this.defaultValue = '请选择'
        this.queryParam = {}
        this.loadData(1);
      },

      //千分位
      formatNumber(num) {
        if (isNaN(num)) {
          throw new TypeError("num is not a number");
        }

        var groups = (/([\-\+]?)(\d*)(\.\d+)?/g).exec("" + num),
          mask = groups[1],            //符号位
          integers = (groups[2] || "").split(""), //整数部分
          decimal = groups[3] || "",       //小数部分
          remain = integers.length % 3;

        var temp = integers.reduce(function(previousValue, currentValue, index) {
          if (index + 1 === remain || (index + 1 - remain) % 3 === 0) {
            return previousValue + currentValue + ",";
          } else {
            return previousValue + currentValue;
          }
        }, "").replace(/\,$/g, "");
        return mask + temp + decimal;
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>